class Solution(object):
    def canFinish(self, numCourses, prerequisites):
        """
        :type numCourses: int
        :type prerequisites: List[List[int]]
        :rtype: bool
        """
        map = [0]*numCourses
        for i in prerequisites:
            map[i[1]] += 1
        queue = []
        count = 0
        for i in range(0, len(map)):
            if map[i] == 0:
                count += 1
                queue.append(i)
                #   出度为0的进队列
        while queue:
            now = queue.pop()
            for i in range(0, len(prerequisites)):
                if prerequisites[i][0] == now:
                    map[prerequisites[i][1]] -= 1
                    if map[prerequisites[i][1]] == 0:
                        queue.append(prerequisites[i][1])
                        count += 1
        return count == numCourses
